package com.sooth.system.dict.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.dream.system.config.Page;
import com.sooth.common.core.domain.R;
import com.sooth.common.dream.model.PageModel;
import com.sooth.common.log.annotation.Log;
import com.sooth.common.web.core.BaseController;
import com.sooth.system.dict.service.ISysDictTypeService;
import com.sooth.system.dict.view.SysDictTypeBo;
import com.sooth.system.dict.view.SysDictTypeDto;
import com.sooth.system.dict.view.SysDictTypeVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 数据字典信息
 *
 * @author Lion Li
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/dict-type")
public class SysDictTypeController extends BaseController {

    private final ISysDictTypeService dictTypeService;

    /**
     * 查询字典类型列表
     */
    @SaCheckPermission("system:dict:query")
    @GetMapping("/list")
    public R<Page<SysDictTypeVo>> list(SysDictTypeDto dictTypeModel, PageModel pageModel) {
        return R.ok(dictTypeService.selectPage(dictTypeModel, pageModel));
    }

    /**
     * 查询字典类型列表
     */
    @SaCheckPermission("system:dict:query")
    @GetMapping("/listAll")
    public R<List<SysDictTypeVo>> listAll(SysDictTypeDto dictTypeModel) {
        return R.ok(dictTypeService.selectList(dictTypeModel));
    }

    /**
     * 查询字典类型详细
     *
     * @param id 字典ID
     */
    @SaCheckPermission("system:dict:query")
    @GetMapping(value = "/query")
    public R<SysDictTypeBo> query(@RequestParam Long id) {
        return R.ok(dictTypeService.selectById(id));
    }

    /**
     * 新增字典类型
     */
    @SaCheckPermission("system:dict:add")
    @Log(title = "数据字典", message = "新增字典类型")
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysDictTypeBo dictTypeBo) {
        return toAjax(dictTypeService.insert(dictTypeBo));
    }

    /**
     * 修改字典类型
     */
    @SaCheckPermission("system:dict:edit")
    @Log(title = "数据字典", message = "修改字典类型")
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody SysDictTypeBo dictTypeBo) {
        return toAjax(dictTypeService.updateById(dictTypeBo));
    }

    /**
     * 删除字典类型
     *
     * @param id 字典ID串
     */
    @SaCheckPermission("system:dict:remove")
    @Log(title = "数据字典", message = "删除字典类型")
    @DeleteMapping("/remove")
    public R<Void> remove(@RequestParam Long id) {
        return toAjax(dictTypeService.deleteById(id));
    }

}
